import axios from 'axios'

// 请求拦截
axios.interceptors.request.use(config => {
  console.log(config.url)
  config.headers.Authorization = window.sessionStorage.getItem('token') || ''//携带用户信息
  return config;
}, error => {

  return Promise.reject(error);
});

// 响应拦截
axios.interceptors.response.use(response => {
  //响应成功返回数据
   if(response.data.success){
    return response.data.result
  }
  //响应失败提示报错
   if (!response.data.result) {
    console.log(response.data.message)
    return Promise.reject(response.data.message)
  }
  //响应成功返回数据
  if(response.data.data){
    return response.data
  }
  
}, error => {
  //接口报错
  console.log(error)
  return Promise.reject(error)
})



export default axios